package com.example.systemserver.controller;

import cn.hutool.jwt.JWTUtil;
import com.example.systemserver.bean.RequestBean;
import com.example.systemserver.service.PersonService;
import com.example.systemserver.bean.ResultBean;
import com.example.systemserver.bean.PersonBean;
import com.github.pagehelper.PageInfo;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.nio.charset.StandardCharsets;

@Slf4j
@RestController
@RequestMapping("/person")
public class PersonController {
   // title=小红&age=18&gender=女&address=上海
  //  {title:小王,age:18,gender:女,address:上海}

    @Autowired
    private PersonService personService;

    @RequestMapping("/save")
    public ResultBean save(@RequestBody PersonBean requestBean){
        log.info("/person/save,学员保存,请求参数:{}",requestBean);
        personService.save(requestBean);
        log.info("/person/save,学员保存完成,返回值:null");
        return new ResultBean(200, "保存成功", null);
    }
    @RequestMapping("/remove")
    public ResultBean remove(@RequestBody PersonBean requestBean){
        log.info("/person/remove,学员删除,请求参数:{}",requestBean);
        personService.remove(requestBean);
        log.info("/person/remove,学员删除,返回值:null");
        return new ResultBean(200, "删除成功", null);
    }

    @RequestMapping("/list") //
    public ResultBean list(@RequestBody RequestBean<PersonBean> requestBean){
        log.info("/person/list,学员列表,请求参数:{}",requestBean);
        PageInfo<PersonBean> pageInfo = personService.list(requestBean);
        ResultBean resultBean = new ResultBean(200, "查询成功", pageInfo);
        log.info("/person/list,学员列表完成,返回值:{}",resultBean);
        return resultBean;
    }

    @RequestMapping("/info")
    public ResultBean info(@RequestBody PersonBean requestBean){
        log.info("/person/info,学员详情,请求参数:{}",requestBean);
        PersonBean personBean = personService.info(requestBean);

        ResultBean resultBean = new ResultBean(200,"查询成功",personBean);
        log.info("/person/info,学员详情完成,返回值:{}",resultBean);
        return resultBean;
    }
}
